package com.zy.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.business.domain.TbProjectFollow;
import com.zy.business.domain.TbProjectOperRecord;
import com.zy.business.mapper.ProjectFollowMapper;
import com.zy.business.mapper.ProjectOperRecordMapper;
import com.zy.business.service.ProjectFollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @description: 客户跟进记录实现类
 * @author: whf
 * @create: 2023-02-24 10:06
 **/
@Service
public class ProjectFollowServiceImpl extends ServiceImpl<ProjectFollowMapper, TbProjectFollow> implements ProjectFollowService {

    @Autowired
    private ProjectOperRecordMapper operRecordMapper;

    @Override
    @Transactional
    public int add(TbProjectFollow projectFollow) {
        projectFollow.setCreateTime(new Date());
        int row = baseMapper.insert(projectFollow);
        TbProjectOperRecord record = new TbProjectOperRecord();
        record.setProjectId(projectFollow.getProjectId());
        record.setMsg("新增跟进记录");
        record.setCreateBy(projectFollow.getCreateBy());
        record.setCreateTime(new Date());
        operRecordMapper.insert(record);
        return row;
    }

    @Override
    public List<TbProjectFollow> selectList(Long projectId) {
        return baseMapper.selectList(new QueryWrapper<TbProjectFollow>().eq("project_id", projectId).orderByDesc("create_time"));
    }
}
